class Enemy extends imageClass{
    constructor(game, name){
        super(game, name)
        this.game = game
        this.setup()
    }
    setup(){
        this.x = randomBetween(1, 500 - this.w) 
        this.y = -randomBetween(this.h, this.h+250)
        this.speed = randomBetween(1,3)
    }
    update (){
        /* 更新敌机位置 */
        this.y += this.speed
        if (this.y > 600){
            this.setup()
        }

        // 击中判断
        var b = this.collide()
        if (b){
            // 删除子弹
            this.scene.bullet.remove(b)
            // 爆炸效果
            var x = this.x + this.w/2
            var y = this.y + this.h/2
            var bomb = Bomb.new(this.game, x, y)
            this.scene.addArray(bomb, this.scene.bomb)
            var audio = document.createElement("audio")
            audio.src = "audio/bomb.wav"
            audio.play()
            // 更新飞机
            this.setup()
        }
    }
    collide(){
        for (var b of this.scene.bullet){
            if (collide(this, b)){
                return b
            }
        }
        return false
    }
}